<?php
$id_image = $_GET['id'];
$photo_one = $tc->photo_one($id_image,$user);
$row_photo_one = mysql_fetch_array($photo_one);

$file = url_hinh_photo_full.$row_photo_one['name'].'.jpg';

$size_info = getimagesize($file);
$width = $size_info[0];
$height = $size_info[1];
if($width>$height && $width>=700){
	$padding_h = ((500-$height)/2);
	$padding = "padding:{$padding_h}px 0";
}
elseif($width<$height && $height>=500){
	$padding_w = ((700-$width)/2);
	$padding = "padding:0 {$padding_w}px";
}
else{
	$padding_w = ((700-$width)/2);
	$padding_h = ((500-$height)/2);
	$padding = "padding:{$padding_h}px {$padding_w}px";
}
?>
<div id="popupContact">
    <div id="content_pic">
    	<div class="pic_one"><?php echo '<img style="'.$padding.'" id="show_picture" src="'.$file.'" alt="'.$row_photo_one['name'].'" />'; ?></div>
        
        <div class="comment_pic">
        	<a id="popupContactClose">[x]</a>
            <?php
			if($row_photo_one['info']!=NULL) $info_photo = $row_photo_one['info']; else $info_photo = 'Thêm mô tả';
			(($tc->check_like_photos($row_photo_one['id'],$idUser))==0) ? $like='Thích' : $like='Bỏ thích';
			$total_like = count(explode(' || ',$row_photo_one['user_like']))-1;
			($total_like != 0) ? $total_like='Có '.$total_like.' người thích đều này' : $total_like='';
			
			$user_comment = $tc->user_info($row_photo_one['user_id']);
			$user_comment = mysql_fetch_array($user_comment);
			
			$view_cm = '<div class="info">
                <div class="title"> <div class="icon"><img src="'.url_hinh_user_40x40.$user_comment['avatar'].'.jpg" alt="'.$user_comment['name'].'" /></div> <div class="name"><a href="index.html?user='.$row_photo_one['user_id'].'">'.$user_comment['name'].'</a></div><div class="date">'.$tc->wall_datetime($row_photo_one['date_create']).'</div></div>
                <div class="content">'.$info_photo.'</div>
                <div class="action"><a href="javascript:;" class="like like_'.$row_photo_one['id'].'">'.$like.'</a> &nbsp; <a href="javascript:;" class="binhluan '.$row_photo_one['id'].'">Bình luận</a><span style="color:#999; padding-left:10px">'.$total_like.'</span></div>
            </div><div id="content_photo"><div id="ajax_cm_photo"></div>';
			$comment = $tc->view_comment_photo($row_photo_one['id']); 
			if(mysql_num_rows($comment)==1){
				$row_comment = mysql_fetch_array($comment);
				$m_comment = explode(' |-| ',$row_comment['comment']);
				$m_user_id = explode(' |-| ',$row_comment['user_id']);
				$m_date_create = explode(' |-| ',$row_comment['date_create']);
				for($i=count($m_comment)-1; $i>0; $i--){
					$user_comment = $tc->user_info($m_user_id[$i]);
					$user_comment = mysql_fetch_array($user_comment);
					$view_cm .= '<div class="comment">
					<div class="comment_img"><a href="index.html?user='.$m_user_id[$i].'"><img src="'.url_hinh_user_40x40.$user_comment['avatar'].'.jpg" alt="'.$user_comment['name'].'"></a></div>
					<div class="comment_photo">
						<a href="index.html?user='.$m_user_id[$i].'"><strong>'.$user_comment['name'].'</strong></a> '.$m_comment[$i].'
						<div class="date">'.$tc->wall_datetime($m_date_create[$i]).'</div>
					</div>
					<div style="clear:both; height:1px"></div>
					</div>';
				}
			}
			if(@$idUser) $wall_comment = '<div class="comment"><div class="comment_img"><a href="#"><img src="'.$avatar.'" alt=""> </a></div><div class="comment_photo">
			<input type="text" name="comment" value="Viết bình luận" id="comment'.$row_photo_one['id'].'" class="frmcomment_photo" /></div><div style="clear:both; height:1px"></div></div>';
			echo $view_cm .= '</div>'.$wall_comment;
			?>
        </div>
        <div style="clear:both; height:1px"></div>
    </div>
</div>
<div id="backgroundPopup"></div>
<script type="text/javascript">
$(document).ready(function() {
    centerPopup("absolute");
    loadPopup();
    $("#popupContactClose").click(function() {
        disablePopup();
		window.history.go(-1)
    });
    $("#backgroundPopup").click(function() {
        disablePopup();
		window.history.go(-1)
    });
	
	$("input[name=comment], .binhluan").click(function(){
		var comment = $("input[name=comment]").val();
		if(comment=='Viết bình luận') $("input[name=comment]").val("");
		$("input[name=comment]").focus();
	});
	$("input[name=comment]").keydown(function(e){
		var key = e.keyCode;
		if(key==13){
			var comment = $(this).val();
			$(this).attr("readonly",true);
			$.post("ajax.php",{comment_photo:"comment_photo",id:<?php echo $id_image ?>,cm:comment},function(data){
				var str = '<div class="comment"><div class="comment_img"><a href="index.html?user=<?php echo $idUser?>"><img src="<?php echo $avatar?>" alt="" /></a></div><div class="comment_photo"><a href="index.html?user=<?php echo $idUser?>"><strong><?php echo $_SESSION['name']?></strong></a> ' + comment + '<div class="date"></div></div><div style="clear:both; height:1px"></div></div>';
				$("#ajax_cm_photo").prepend(str);
				$("input[name=comment]").val('');
				setTimeout(function(){$("input[name=comment]").attr("readonly",false);},500);
			});
		}
	});
});
</script>
<script type="text/javascript">
$(document).ready(function(){
	$('.like').click(function(){
		var id = ($(this).attr('class')).split("_");
		var name = ($(this).attr('class')).split(" ");
		$.post("like.php",{user_like_photo:"user_like_photo",id:id[1],id2:<?php echo $idUser?>},function(){
			if($('.'+name[1]).html()=='Thích') $('.'+name[1]).html('Bỏ thích');
			else $('.'+name[1]).html('Thích');
		});
	});
});
</script>